home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tclX6.4c / dist / tests / testlib.tcl < prev    next >
Encoding:
Text File  |  1992-11-07  |  3.3 KB  |  101 lines

  1. #
  2. # testlib.tcl --
  3. #
  4. # Test support routines.  Some of these are based on routines provided with
  5. # standard Tcl.
  6. #------------------------------------------------------------------------------
  7. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  8. #
  9. # Permission to use, copy, modify, and distribute this software and its
  10. # documentation for any purpose and without fee is hereby granted, provided
  11. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  12. # Mark Diekhans make no representations about the suitability of this
  13. # software for any purpose.  It is provided "as is" without express or
  14. # implied warranty.
  15. #------------------------------------------------------------------------------
  16. # $Id: testlib.tcl,v 2.0 1992/10/16 04:49:22 markd Rel $
  17. #------------------------------------------------------------------------------
  18. #
  19.  
  20.  
  21. rename unknown SAVED_UNKNOWN
  22.  
  23. #
  24. #
  25. proc OutTestError {test_name test_description contents_of_test
  26.                    passing_int_result passing_result int_result result} {
  27.     set int(0) TCL_OK
  28.     set int(1) TCL_ERROR
  29.     set int(2) TCL_RETURN
  30.     set int(3) TCL_BREAK
  31.     set int(4) TCL_CONTINUE
  32.  
  33.     puts stdout "==== $test_name $test_description"
  34.     puts stdout "==== Contents of test case:"
  35.     puts stdout "$contents_of_test"
  36.     puts stdout "==== Result was: $int($int_result)"
  37.     puts stdout "$result"
  38.     puts stdout "---- Result should have been: $int($passing_int_result)"
  39.     puts stdout "$passing_result"
  40.     puts stdout "---- $test_name FAILED" 
  41.  
  42. }
  43.  
  44. proc test {test_name test_description contents_of_test passing_results} {
  45.     set answer [uplevel $contents_of_test]
  46.     if {$answer != $passing_results}  { 
  47.         puts stdout "==== $test_name $test_description"
  48.         puts stdout "==== Contents of test case:"
  49.         puts stdout "$contents_of_test"
  50.         puts stdout "==== Result was:"
  51.         puts stdout "$answer"
  52.     puts stdout "---- Result should have been:"
  53.     puts stdout "$passing_results"
  54.     puts stdout "---- $test_name FAILED" 
  55.     }
  56. }
  57.  
  58. proc Test {test_name test_description contents_of_test passing_int_result
  59.            passing_result} {
  60.     set int_result [catch {uplevel $contents_of_test} result]
  61.  
  62.     if {($int_result != $passing_int_result) ||
  63.         ($result != $passing_result)} {
  64.         OutTestError $test_name $test_description $contents_of_test \
  65.                      $passing_int_result $passing_result $int_result $result
  66.     }
  67. }
  68.  
  69. #
  70. # Compare result against case-insensitive regular expression.
  71. #
  72.  
  73. proc TestReg {test_name test_description contents_of_test passing_int_result
  74.               passing_result} {
  75.     set int_result [catch {uplevel $contents_of_test} result]
  76.  
  77.     if {($int_result != $passing_int_result) ||
  78.         ![regexp -nocase $passing_result $result]} {
  79.         OutTestError $test_name $test_description $contents_of_test \
  80.                      $passing_int_result $passing_result $int_result $result
  81.     }
  82. }
  83.  
  84. proc dotests {file args} {
  85.     global TESTS
  86.     set savedTests $TESTS
  87.     set TESTS $args
  88.     source $file
  89.     set TESTS $savedTests
  90. }
  91.  
  92. # Genenerate a unique file record that can be verified.  The record
  93. # grows quite large to test the dynamic buffering in the file I/O.
  94.  
  95. proc GenRec {id} {
  96.     return [format "Key:%04d {This is a test of file I/O (%d)} KeyX:%04d %s" \
  97.                     $id $id $id [replicate :@@@@@@@@: $id]]
  98. }
  99.  
  100.